import React, { useEffect } from 'react';
import { Form, Input, DatePicker, Select, Radio } from 'antd';
import { SearchInput } from '@/components/UserForm';
import AdvancedSearch from '@/components/AdvancedSearch';
import { getemployeelist } from '@/services/attendance/overtime';
// import { withRouter } from 'umi';

const { RangePicker } = DatePicker;
const { Option } = Select;

const SearchForm = ({ form, onSearch, user, candidateAgreeType, candidateSexType }) => {
    // const { query } = location;
    const { getFieldDecorator } = form;
    const getCandidateAgreeType = () =>
        candidateAgreeType.map(item => {
            if (item.dictValue === '0') {
                return '';
            }
            return (
                <Option value={item.dictValue} key={item.dictValue}>
                    {item.dictName}
                </Option>
            );
        });
    const getCandidateSexType = () =>
        candidateSexType.map(item => {
            if (item.dictValue === '3') {
                return '';
            }
            return (
                <Radio value={item.dictValue} key={item.dictValue}>
                    {item.dictName}
                </Radio>
            );
        });
    const handleSubmit = e => {
        form.validateFields(err => {
            if (!err) {
                // onSearch(values);
                onSearch(e);
            }
        });
    };
    useEffect(() => {}, []);
    return (
        // <AdvancedSearch
        //     isCollapsed={!query.companyId}
        //     baseForm={baseForm}
        //     collapsedFrom={collapsedFrom}
        //     reset={() => form.resetFields()}
        //     submit={() => handleSubmit()}
        // />
        <AdvancedSearch
            form={form}
            onSubmit={() => handleSubmit({ eType: 'submit' })}
            onReset={() => handleSubmit({ eType: 'reset' })}
            // expand={!collapsed}
            // colConfig={{
            //     xxl: 8,
            //     xl: 12,
            //     lg: 24,
            //     md: 24,
            //     sm: 24,
            //     xs: 24
            // }}
        >
            <Form.Item label="姓名">
                {getFieldDecorator('searchName', {})(<Input placeholder="请输入姓名" allowClear />)}
            </Form.Item>
            <Form.Item label="手机">
                {getFieldDecorator('talentPhone', {})(<Input placeholder="请输入手机号码" allowClear />)}
            </Form.Item>
            <Form.Item label="邮箱">
                {getFieldDecorator('talentEmail', {})(<Input placeholder="请输入邮箱" allowClear />)}
            </Form.Item>
            <Form.Item label="性别">
                {getFieldDecorator('talentSex', {})(<Radio.Group>{getCandidateSexType()}</Radio.Group>)}
            </Form.Item>
            <Form.Item label="入库时间">{getFieldDecorator('insertDate', {})(<RangePicker />)}</Form.Item>
            <Form.Item label="最高学历">
                {getFieldDecorator('talentDegree', { initialValue: undefined })(
                    <Select placeholder="请选择" allowClear>
                        {getCandidateAgreeType()}
                    </Select>
                )}
            </Form.Item>
            <Form.Item label="就职职位">
                {getFieldDecorator('lastPost', {})(<Input placeholder="请输入就职职位" allowClear />)}
            </Form.Item>
            <Form.Item label="简历管理人">
                {getFieldDecorator('talentLeaderId', {
                    initialValue: undefined
                })(
                    <SearchInput
                        params={{
                            companyId: user.companyId
                        }}
                        requireParam={['companyId']}
                        getData={params =>
                            getemployeelist(params).then(res => {
                                if (res && res.code === 10000) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        selectProps={{
                            placeholder: '请输入员工姓名',
                            allowClear: true
                        }}
                        fieldsName={{
                            value: 'id',
                            title: 'employeeName',
                            extraParams: 'userName'
                            // isBuLu: true
                        }}
                    />
                )}
            </Form.Item>
        </AdvancedSearch>
    );
};
export default SearchForm;
